<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="static/assets/global/plugins/bootstrap/css/bootstrap.min.css"/>
	<link rel="stylesheet" type="text/css" href="static/assets/global/css/components.css"/>
	<link rel="stylesheet" type="text/css" href="static/assets/admin/pages/css/login.css"/>
	<script type="text/javascript" src="static/assets/global/plugins/jquery-1.11.0.min.js"></script>
	<title></title>

</head>
<body class="login">
	<div class="content">
		<h3 class="form-title">创建商品</h3>
		<div class="form-group">
			<label class="control-label">商品名</label>
			<div>
				<input class="form-control" type="text" placeholder="商品名" id="title" name="title"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label">商品描述</label>
			<div>
				<input class="form-control" type="text" placeholder="商品描述" id="description" name="description"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label">价格</label>
			<div>
				<input class="form-control" type="text" placeholder="价格" id="price" name="price"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label">图片</label>
			<div>
				<input class="form-control" type="text" placeholder="图片" id="imgUrl" name="imgUrl"/>
			</div>
		</div>
		<div class="form-group">
			<label class="control-label">库存</label>
			<div>
				<input class="form-control" type="text" placeholder="库存" id="stock" name="stock"/>
			</div>
		
		<div class="form-actions">
			<button class="btn blue" id="create" type="submit">
				创建商品
			</button>
		</div>
	</div>
</body>
<script>
	jQuery(document).ready(function(){

		//绑定otp的click事件用于向后端发送获取手机号验证码的请求
		$("#create").on("click",function(){
			var title = $("#title").val();
			var description = $("#description").val();
			var imgUrl = $("#imgUrl").val();
			var price = $("#price").val();
			var stock = $("#stock").val();
			
			if(title==null || title==""){
				alert("商品名不能为空！");
				return false;
			}
			if(description==null || description==""){
				alert("描述不能为空！");
				return false;
			}
			if(imgUrl==null || imgUrl==""){
				alert("图片不能为空！");
				return false;
			}
			if(price==null || price==""){
				alert("价格不能为空！");
				return false;
			}
			if(stock==null || stock==""){
				alert("库存不能为空！");
				return false;
			}
			
			$.ajax({
				type:"POST",
				contenttype:"application/x-www-form-urlencoded",
				url:"http://localhost:8090/item/create",
				data:{
					"title":title,
					"description":description,
					"imgUrl":imgUrl,
					"price":price,
					"stock":stock
				
				},
				xhrFields:{withCredentials:true},
				success:function(data){
					if(data.status =="success"){
						alert("创建成功！");
					}else{
						alert("创建失败！原因为"+data.data.errMsg);
					}

				},
				error:function(data){
					alert("创建失败！原因为"+data.responseText);
				}
			});
			return false;
		});
	});

</script>
</html>